package com.liner.homework;


import java.util.Scanner;

public class Homework01 {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
       /* 1. CommandBySwitch命令解析程序：

        要求：接收用户输入的命令，依据命令做不同的操作

        */

        //第1遍
        String account, password, name, phone, card, cardType, cardNumber;
        double money = 0.0;

        System.out.println("欢迎使用XX银行管理系统");
        System.out.println("请输入您要执行的命令(1.开通账户 2.查询账号余额 3.存款 4.取款 5.退出系统)：");
        int num = scanner.nextInt();
        switch (num) {
            case 1:
                System.out.println("请输入您要开通的账户的账号：");
                account = scanner.next();
                System.out.println("请输入您要开通的账户的密码：");
                password = scanner.next();
                System.out.println("请输入您要开通的账户的姓名：");
                name = scanner.next();
                System.out.println("请输入您要开通的账户的手机号码：");
                phone = scanner.next();
                System.out.println("请输入您要开通的账户的银行卡号：");
                card = scanner.next();
                System.out.println("请输入您要开通的账户的银行卡类型：");
                cardType = scanner.next();
                System.out.println("请输入您要开通的账户的银行卡尾号：");
                cardNumber = scanner.next();
                break;
            case 2:
                System.out.println("请输入您要查询的账号的账号：");
                account = scanner.next();
                System.out.println("请输入您要查询的账号的密码：");
                password = scanner.next();
                break;
            case 3:
                System.out.println("请输入您要存款的金额：");
                money = scanner.nextDouble();
                break;
            case 4:
                System.out.println("请输入您要取款的金额：");
                money = scanner.nextDouble();
                break;
            case 5:
                System.out.println("退出系统");
                break;
            default:
                System.out.println("输入错误，请重新输入");
                break;
        }


        //第2遍
        System.out.println("欢迎使用XX银行管理系统");
        System.out.println("请输入您要执行的命令(1.开通账户 2.查询账号余额 3.存款 4.取款 5.退出系统)：");
        num = scanner.nextInt();
        switch (num) {
            case 1:
                System.out.println("开通账户");
                break;
            case 2:
                System.out.println("查询账号余额");
                break;
            case 3:
                System.out.println("存款业务");
                break;
            case 4:
                System.out.println("取款业务");
                break;
            case 5:
                System.out.println("退出系统");
                break;
            default:
                System.out.println("输入错误，请重新输入");
                break;
        }





        /*2. Guessing猜数字之while版：

        要求：随机生成一个数，由用户来猜，猜不对则反复猜，并给出大小提示，猜对的则结束，用while来实现。

        */
        //第1遍
        int count = 0;
        int random = (int) (Math.random() * 100 + 1);
        System.out.print("猜个数字试试吧(你只有10次机会):");
        int guess = scanner.nextInt();
        while (true) {
            if (guess > num) {
                System.out.println("猜大了");
            } else if (guess < num) {
                System.out.println("猜小了");
            } else {
                System.out.println("恭喜你猜对了");
                break;
            }
            System.out.println("当前剩余次数:" + --count);
            if (count == 0) {
                System.out.println("机会用光了");
                break;
            }
            System.out.print("再猜个数字试试吧:");
            guess = scanner.nextInt();

        }
        System.out.println("本次所用次数:" + (10 - count));


        //第2遍
        System.out.println("猜个数字吧：");
        guess = scanner.nextInt();
        while (guess != random) {

            if (guess > random) {
                System.out.println("猜大了");
            } else {
                System.out.println("猜小了");
            }
            System.out.println("猜个数字吧：");
            guess = scanner.nextInt();
        }
        System.out.println("猜对了");



        /*3. Guessing猜数字之do...while版

        要求：随机生成一个数，由用户来猜，猜不对则反复猜，并给出大小提示，猜对的则结束，用do...while来实现。

        */
        //第1遍
        count = 0;
        do {
            System.out.print("猜个数字试试吧(你只有10次机会):");
            guess = scanner.nextInt();
            if (guess > num) {
                System.out.println("猜大了");
                System.out.println("当前剩余次数:" + --count);
            } else if (guess < num) {
                System.out.println("猜小了");
                System.out.println("当前剩余次数:" + --count);
            } else {
                System.out.println("恭喜你猜对了");
                System.out.println("你所用次数是:" + (10 - count));
            }
            if (count == 0) {
                System.out.println("对不起，次数用尽");
                break;
            }
        } while (guess != num);


        //第2遍
        do {
            System.out.println("猜个数字吧：");
            guess = scanner.nextInt();
            if (guess > random) {
                System.out.println("猜大了");
            } else if (guess < random) {
                System.out.println("猜小了");
            } else {
                System.out.println("猜对了");
            }
        } while (guess != random);






        /*4. for循环：输出5次"行动是成功的阶梯"、输出9的乘法表(1到9、1/3/5/7/9、9到1)、1到100的累加和*/
        //第1遍
        for (int i = 1; i <= 5; i++) {
            System.out.println("第" + i + "遍：行动是成功的阶梯");
        }

        System.out.println("++++++++++++++++++++++++++++");
        for (int i = 1; i <= 9; i++) {
            System.out.println(i + " * 9 = " + 9 * i);

        }
        System.out.println("~~~~~~~~~~~~~");
        for (int i = 9; i >= 1; i--) {
            System.out.println(i + " * 9 = " + 9 * i);

        }
        System.out.println("~~~~~~~~~~~~~");
        for (int i = 1; i <= 9; i += 2) {
            System.out.println(i + " * 9 = " + 9 * i);

        }
        System.out.println("++++++++++++++++++++++++++++");

        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println("sum = " + sum);


        //第2遍
        for (int i = 0; i < 5; i++) {
            System.out.println("行动是成功的阶梯");
        }

        System.out.println("++++++++++++++++++++++++++++");
        for (int i = 1; i <= 9; i++) {
            System.out.println("9 * " + i + " = " + 9 * i);

        }
        System.out.println("~~~~~~~~~~~~~");
        for (int i = 9; i >= 1; i--) {
            System.out.println("9 * " + i + " = " + 9 * i);

        }
        System.out.println("~~~~~~~~~~~~~");
        for (int i = 1; i <= 9; i += 2) {
            System.out.println("9 * " + i + " = " + 9 * i);

        }
        System.out.println("++++++++++++++++++++++++++++");

        sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum = sum + i;
        }
        System.out.println("sum = " + sum);

    }
}
